<?php
/* SVN FILE: $Id: lil_wysiwyg_plugin_controller.php 162 2009-10-14 19:48:36Z miha@nahtigal.com $ */
/**
 * Short description for lil_wysiwyg_plugin_controller.php
 *
 * Long description for lil_wysiwyg_plugin_controller.php
 *
 * PHP versions 4 and 5
 *
 * Copyright (c) 2009, Miha Nahtigal
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright     Copyright (c) 2009, Miha Nahtigal
 * @link          http://www.nahtigal.com/
 * @package       lil_wysiwyg_plugin
 * @subpackage    lil_wysiwyg_plugin
 * @since         v 1.0
 * @version       $Revision: 162 $
 * @modifiedby    $LastChangedBy: miha@nahtigal.com $
 * @lastmodified  $Date: 2009-10-14 21:48:36 +0200 (sre, 14 okt 2009) $
 * @license       http://www.opensource.org/licenses/mit-license.php The MIT License
 */
App::import('Controller', 'Lil.LilPlugin');
/**
 * LilBlogsWysiwygPluginController class
 *
 * @uses          LilBlogsWysiwygPluginController
 * @package       lil_wysiwyg_plugin
 * @subpackage    lil_wysiwyg_plugin
 */
class LilBlogsWysiwygPluginController extends LilPluginController {
	var $name = 'LilBlogsWysiwygPlugin';
/**
 * handlers property
 *
 * @var array
 * @access public
 */
	var $handlers = array(
		'form_edit_post' => array('function' => '_initWysiwyg', 'params' => array()),
		'form_add_post' => array('function' => '_initWysiwyg', 'params' => array())
	);
/**
 * _initWysiwyg method
 *
 * This replaces textarea with CKEditor and sets properties
 *
 * @param mixed $model
 * @access public
 * @return void
 */
	function _initWysiwyg($view, $form_data) {
		$form_data['form']['post'] .= 
			$view->Html->script(Router::url('/', true) . 'lil_blogs_wysiwyg/js/ckeditor/ckeditor.js') . PHP_EOL . 
			'<script type="text/javascript">' . PHP_EOL . 
			'	CKEDITOR.addStylesSet(\'lil_blogs_wysiwyg_styles\', ' . PHP_EOL .
					json_encode(Configure::read('LilBlogsWysiwyg.styles')) . PHP_EOL .
			'	);' . PHP_EOL .
			'	CKEDITOR.replace(\'data[Post][body]\', {' . PHP_EOL .
			'		toolbar: [[\'Styles\',\'-\',\'Bold\',\'Italic\',\'Underline\',\'Strike\',\'-\',\'NumberedList\',\'BulletedList\',\'-\',\'Link\',\'Unlink\',\'Image\',\'Table\',\'-\',\'Undo\',\'Redo\',\'RemoveFormat\',\'-\',\'Source\']], ' . PHP_EOL .
			'		entities: false,' . PHP_EOL .
			(($css = Configure::read('LilBlogsWysiwyg.css')) ? '		contentsCss: ' . json_encode(Router::url($css, true)). ',' : '') .
			'		width: 605,' . PHP_EOL .
			'		height: 400,' . PHP_EOL .
			'		resize_maxWidth: 605,' . PHP_EOL .
			'		resize_minWidth: 600,' . PHP_EOL .
			'		customConfig : \'\',' . PHP_EOL .
			((in_array('Media', (array)Configure::read('Lil.plugins')))
				? 
					'		filebrowserBrowseUrl : \'' . Router::url(array('plugin' => 'lil_media', 'admin' => true, 'controller' => 'media', 'action' => 'browse')) . '\',' . PHP_EOL .
					'		filebrowserWindowWidth : 640,' . PHP_EOL . 
					'		filebrowserWindowHeight : 480,' . PHP_EOL .
					'		filebrowserImageBrowseUrl : \'' . Router::url(array('plugin' => 'lil_media', 'admin' => true, 'controller' => 'media', 'action' => 'browse')) . '\',' . PHP_EOL .
					'		filebrowserImageWindowWidth : 640,' . PHP_EOL . 
					'		filebrowserImageWindowHeight : 480,' . PHP_EOL
				: ''
			) . PHP_EOL .
			'		stylesCombo_stylesSet : \'lil_blogs_wysiwyg_styles\'' . PHP_EOL .
			'	});' . PHP_EOL . 
			'</script>' . PHP_EOL;
		return $form_data;
	}

}